package com.infinit.selfhelp.common.utils

import android.text.InputFilter
import android.text.Spanned

// 创建一个自定义的 InputFilter，用于阻止输入空格字符

class NoSpaceInputFilter : InputFilter {
    override fun filter(source: CharSequence?, start: Int, end: Int, dest: Spanned?, dstart: Int, dend: Int): CharSequence? {
        for (i in start until end) {
            // 检查是否包含空格字符
            if (source?.get(i) == ' ') {
                return ""
            }
        }
        return null // 接受输入
    }
}

// 创建一个自定义的 InputFilter，只允许输入大小写字母和数字
class AlphanumericInputFilter : InputFilter {
    override fun filter(source: CharSequence?, start: Int, end: Int, dest: Spanned?, dstart: Int, dend: Int): CharSequence? {
        for (i in start until end) {
            // 检查是否不是大小写字母和数字
            if (!Character.isLetterOrDigit(source?.get(i) ?: ' ')) {
                return ""
            }
        }
        return null // 接受输入
    }
}